<template>
	<view class="content">
		<view class="input" v-if="iscenter">
			<view class="">请输入商城id</view>
			<input type="number" v-model="mall_id" placeholder="请输入商城id">
			<view class="btn" @click="btn">
				确认
			</view>
		</view>
		<view class="qrimg" @click="preimg">
			<image class="image" :src="qrimg" mode=""></image>
		</view>
		<!-- <view class="" @click="saveqr">
			保存图片
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				iscenter: false,
				qrimg: '',
				mall_id: 1
			}
		},
		onLoad(options) {
			this.mall_id = options.mall_id || 1
			this.generateqr()
		},
		methods: {
			btn() {
				this.generateqr()
			},
			generateqr() {
				let qrpath = 'pages/entity/index'
				this.$request({
					url: this.$api.generate.appcode,
					method: 'post',
					data: {
						path: qrpath,
						width: '750',
						scene: "mall_id=" + this.mall_id
					},
				}).then(response => {
					// console.log(response);
					if (response.code === 0) {
						this.qrimg = response.data.qrcode;
					} else {
						uni.showToast({
							title: response.msg,
							icon: 'none',
							duration: 1000,
						});
					}
				}).catch(() => {});
			},
			preimg() {
				uni.previewImage({
					urls: this.qrimg.split(),
					success: res => {
						console.log(res);
					},
					fail: err => {
						console.log(err);
					}
				})
			},
			saveqr() {
				uni.saveImageToPhotosAlbum({ // 不支持网络路径
					filePath: this.qrimg,
					success: res => {
						console.log(res);
					},
					fail: res => {
						console.log(res);
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		width: 100%;
		margin: 0 auto;
		background-color: #fff;
		height: 100vh;

		.input {
			width: 702rpx;
			margin: 0 auto 36rpx;
			font-size: 24rpx;

			&>input {
				margin-top: 24rpx;
				background-color: #f7f7f7;
				padding: 0 24rpx;
				border-radius: 12rpx;
				height: 80rpx;
				line-height: 80rpx;
			}

			.btn {
				font-size: 28rpx;
				border: 1rpx solid #828282;
				border-radius: 8rpx;
				width: 120rpx;
				margin: 24rpx auto;
				text-align: center;
				line-height: 60rpx;
				height: 60rpx;
			}
		}

		.qrimg {
			margin: 0 auto;
			width: 620rpx;
		}

		.image {
			margin: 0 auto;
			width: 620rpx;
			height: 620rpx;
		}
	}
</style>
